package com.qhx.rtkcloud.tcp;

import org.springframework.util.Base64Utils;

import javax.management.*;
import java.io.*;
import java.lang.management.ManagementFactory;
import java.net.Socket;
import java.util.Arrays;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class NtripClientMock {
    private String mount = "mountclient1";

    static String authInfo = "GET /HKLTS HTTP/1.0\n" +
            "User-Agent: NTRIP GNSSInternetRadio/1.4.10\n" +

            "Accept: */*\n" +

            "Connection: close";

    private static String getBase64(String username, String password) {
        return new String(Base64Utils.encode((username + ":" + password).getBytes()));
    }

//    public static void main(String[] args) throws IOException {
//        Socket client = new Socket("82.156.68.184", 2101);
//        InputStream inputStream = client.getInputStream();
//        OutputStream outputStream = client.getOutputStream();
//        outputStream.write((authInfo + "\n\n").getBytes());
//        outputStream.flush();
//        byte[] bytes = new byte[10240];
//        int length = 0;
////        if ((length = inputStream.read(bytes)) > 0) {
////            String info = new String(Arrays.copyOfRange(bytes, 0, length));
////            System.out.println(info);
////        }
//
//        new Thread(() -> {
//            int len = 0;
//            try {
//                while ((len = inputStream.read(bytes)) > 0) {
//                    System.out.println(Arrays.toString(Arrays.copyOfRange(bytes, 0, len)));
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//
//        }).start();
//
//
//        /*Executors.newScheduledThreadPool(1)
//                .scheduleAtFixedRate(() -> {
//                    try {
//                        outputStream.write(new byte[]{7, 8, 9, 10, 11, 12});
//                        outputStream.flush();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }, 1, 1, TimeUnit.SECONDS);*/
//
//    }

    public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException {
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        mBeanServer.registerMBean(new Hello(),         new ObjectName("com.example:type=Hello"));
        try {
            Thread.sleep(Long.MAX_VALUE);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
